package com.shop.technicalservice.dao.favorite.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.favorite.FavoritesDao;
import com.shop.technicalservice.model.favorite.Favorites;

/**
 * A data access object (DAO) providing persistence and search support for
 * Favorites entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see org.rjb.pojo.FavoritesDto
 * @author MyEclipse Persistence Tools
 */

public class FavoritesDaoImpl extends HibernateDaoSupport implements FavoritesDao{
	private static final Log log = LogFactory.getLog(FavoritesDaoImpl.class);
	// property constants
	public static final String USER_NAME = "userName";
	public static final String STATUS = "status";

	protected void initDao() {
		// do nothing
	}

	public Favorites save(Favorites transientInstance)  throws Exception{
		log.debug("saving Favorites instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		return transientInstance;
	}

	public void delete(Favorites persistentInstance)  throws Exception{
		log.debug("deleting Favorites instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Favorites findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Favorites instance with id: " + id);
			Favorites instance = (Favorites) getHibernateTemplate().get(
					"org.rjb.Favorites", id);
			return instance;
	}

	public List findByExample(Favorites instance)  throws Exception{
		log.debug("finding Favorites instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value) throws Exception {
		log.debug("finding Favorites instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Favorites as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByUserName(Object userName)  throws Exception{
		return findByProperty(USER_NAME, userName);
	}

	public List findByStatus(Object status)  throws Exception{
		return findByProperty(STATUS, status);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Favorites instances");
			String queryString = "from Favorites";
			return getHibernateTemplate().find(queryString);
	}

	public Favorites merge(Favorites detachedInstance)  throws Exception{
		log.debug("merging Favorites instance");
			Favorites result = (Favorites) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Favorites instance)  throws Exception{
		log.debug("attaching dirty Favorites instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Favorites instance)  throws Exception{
		log.debug("attaching clean Favorites instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}
 
}